﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Demo.Services.Integration.DAO.Impl;
using Demo.Services.Contracts.DTO.Infos;
using Ext.Net.MVC;

namespace Demo.Web.MVC.Controllers
{
    public class AreaController : Controller
    {
        //
        // GET: /Area/

        public ActionResult Index()
        {
            //AreaDAO manager = new AreaDAO();
            //IList<AreaInfo> info;
            //info = manager.GetAreas();
            //return View(info);
            return View();
        }

        public StoreResult GetAreas()
        {
            AreaDAO manager = new AreaDAO();
            IList<AreaInfo> info;
            info = null;
            return new StoreResult(info);
            //return View();
        }

        public ActionResult About()
        {
            return View();
        }
        public ActionResult Details(int id)
        {
            AreaDAO manager = new AreaDAO();
            AreaInfo info;
            info = null;
            return View(info);
        }

        //
        // GET: /Area/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Area/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Terminar flujo desde manager y remover constantes.

                AreaDAO manager = new AreaDAO();
                AreaInfo info = new AreaInfo();

                //info.Id = Convert.ToInt32(collection.Get("Id"));
                info.Description = collection.Get("Descripcion");

                manager.SaveArea(null);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Area/Edit/5

        public ActionResult Edit(int id)
        {
            AreaDAO manager = new AreaDAO();
            AreaInfo info;
            info = null;
            return View(info);
        }

        //
        // POST: /Area/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                AreaDAO manager = new AreaDAO();
                AreaInfo info = new AreaInfo();

                info.Id = Convert.ToInt32(collection.Get("Id"));
                info.Description = collection.Get("Descripcion");

                //manager.UpdateArea(Convert.ToInt32(info.Id), info.Description);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Area/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Area/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                AreaDAO manager = new AreaDAO();
                AreaInfo info = new AreaInfo();

                info.Id = Convert.ToInt32(collection.Get("Id"));
                info.Description = collection.Get("Descripcion");

                manager.DeleteArea(Convert.ToInt32(info.Id));
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

    }
}
